﻿using System;
using System.Collections.Generic;
using System.Text;

namespace MyLibrary.UI
{
    public class UICommon
    {
        /// <summary>
        /// 通过对容器内的所有自定义验证进行验证
        /// </summary>
        /// <param name="container">容器</param>
        /// <returns>是否通过验证</returns>
        public static bool IsValdated(System.Windows.Forms.Control container)
        {
            if (container == null) throw new ArgumentNullException("容器不能为空");

            bool _passed = true;
            foreach (System.Windows.Forms.Control ctrl in container.Controls)
            {
                if (ctrl is MyLibrary.UI.SelfValidateTextBox)
                {
                    MyLibrary.UI.SelfValidateTextBox box = ctrl as MyLibrary.UI.SelfValidateTextBox;
                    if (box.IsValidated == false)
                    {
                        _passed = false;
                        box.SelfValidateTextBox_Validating(box, new System.ComponentModel.CancelEventArgs());
                    }
                }
            }

            return _passed;
        }
    }
}
